package com.example.shixunandjavagotoyangchen.Activity;

import androidx.recyclerview.widget.RecyclerView;
import androidx.recyclerview.widget.StaggeredGridLayoutManager;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import com.example.modelviewpresenter.View.BasterActivity;
import com.example.shixunandjavagotoyangchen.R;
import java.util.ArrayList;
import java.util.List;

public class MainActivity extends BasterActivity implements  FoodContion.aainview {

    List<FoodJavaBean.DataBean>  haoshi;
    Foodbaseadpter foodbaseadpter;
    FoodPresenter presenter;
    boolean ishalazi=true;
    private androidx.recyclerview.widget.RecyclerView maxView;
    private android.widget.EditText maxEditText;
    private android.widget.Button maxButton;

    @Override
    public int BandLayout() {
        return R.layout.activity_main;
    }

    @Override
    public void initView() {
        maxEditText = (EditText) findViewById(R.id.max_EditText);
        maxButton = (Button) findViewById(R.id.max_Button);
        maxView = (RecyclerView) findViewById(R.id.max_View);
        maxView.setLayoutManager(new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL));
        presenter = new FoodPresenter(this,new FoodModel());
        presenter.doinseelt();

    }

    @Override
    public void initDate() {


        maxButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                String s = maxEditText.getText().toString();
                List<FoodJavaBean.DataBean>  wodelist = new ArrayList<>();
                for (int i = 0; i < haoshi.size(); i++) {
                    FoodJavaBean.DataBean www = haoshi.get(i);
                    if (www.getCollect_num().contains(s)){
                        wodelist.add(www);
                    }
                }

                Foodbaseadpter2 foodbaseadpter2 = new Foodbaseadpter2(wodelist);
                maxView.setAdapter(foodbaseadpter2);
                maxView.setLayoutManager(new StaggeredGridLayoutManager(1,StaggeredGridLayoutManager.VERTICAL));
                foodbaseadpter2.notifyDataSetChanged();

            }
        });
    }


    @Override
    public void getinview(List<FoodJavaBean.DataBean> dataBeans) {
        haoshi = dataBeans;
        if (foodbaseadpter==null){
            foodbaseadpter = new Foodbaseadpter(dataBeans);
            maxView.setAdapter(foodbaseadpter);
        }else {
           if (ishalazi){
               foodbaseadpter.getData().clear();
           }
           foodbaseadpter.getData().addAll(dataBeans);
           foodbaseadpter.notifyDataSetChanged();
        }

    }






}
